<template>
    <div>
        <el-form  :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="角色名" prop="roleName">
                <el-input  v-model="ruleForm.roleName"></el-input>
            </el-form-item>

            <el-form-item label="备注" >
                <el-input  v-model="ruleForm.remark"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            </el-form-item>

        </el-form>
    </div>
</template>

<script>
    export default {
        name: "EditRole",
        data(){
            return{
                ruleForm:{},
                rules: {
                    roleName: [
                        { required: true, message: '不能为空', trigger: 'change' }
                    ]
                }
            }
        },
        methods:{
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let role = new URLSearchParams();

                        Object.keys(this.ruleForm).forEach(key=>{
                            role.append(key,this.ruleForm[key])
                        })

                        this.$axios.post("eiderole.action",role).
                        then(request=>{
                            if (request.data.msg="修改成功"){
                                this.$message.success("修改成功")
                                this.$parent.$parent.getdata()
                                this.$parent.$parent.dialogVisible = false;
                            }else {
                                this.$message.error("修改失败")
                            }
                        }).
                        catch()
                    }
                })
            },
            getroles(id){

                let roles = new URLSearchParams();
                roles.append("id",id)

                this.$axios.post("querybyid_roles.action",roles).
                then(request=>{
                    console.log(request.data)
                    this.ruleForm = request.data;
                }).
                catch()
            },
        },
        //钩子函数
        created() {

        }

    }
</script>

<style scoped>

</style>